package cn.iocoder.yudao.module.pay.splitting.convert;

import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.business.basic.convert.SimpleMapperConvert;
import cn.iocoder.yudao.module.pay.framework.impl.mallbook.MallBookPayClientConfig;
import cn.iocoder.yudao.module.pay.splitting.pojo.bo.PaySplittingBO;
import cn.iocoder.yudao.module.pay.splitting.pojo.po.PaySplitting;
import cn.iocoder.yudao.module.pay.splitting.pojo.vo.MallBookSplittingVO;
import cn.iocoder.yudao.module.pay.splitting.pojo.vo.PaySplittingVO;
import org.mapstruct.Mapper;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * 对象转换器
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/07/22
 */
@Mapper
public interface PaySplittingConvert extends SimpleMapperConvert<PaySplittingVO, PaySplitting> {
    PaySplittingConvert INSTANCE = org.mapstruct.factory.Mappers.getMapper(PaySplittingConvert.class);

    default PaySplitting convert(String payNo, Long splitAmount, String splitUserId, MallBookSplittingVO result) {
        PaySplitting paySplitting = new PaySplitting();
        paySplitting.setMerchantNo(MallBookPayClientConfig.Holder.INSTANCE.getMerchantNo());
        paySplitting.setPayNo(payNo);
        paySplitting.setSplitNo(result.getSplitNo());
        paySplitting.setSplitUserId(splitUserId);
        paySplitting.setAmount(splitAmount);
        paySplitting.setStatus(result.getStatus());
        paySplitting.setErrorMsg(result.getChannelErrorMsg());
        paySplitting.setRawData(JSONUtil.toJsonStr(result.getRawData()));
        return paySplitting;
    }

    default PaySplittingBO convert(PaySplitting splitting) {
        if (splitting == null) {
            return null;
        }
        PaySplittingBO paySplittingBO = new PaySplittingBO();
        paySplittingBO.setPayNo(splitting.getPayNo());
        paySplittingBO.setSplitAmount(splitting.getAmount());
        return paySplittingBO;
    }

}
